home *** CD-ROM | disk | FTP | other *** search
Wrap
;; Inferior self mode ;; ;; For running a Self interpreter under Emacs. ;; Hacked my Michael Richardson <mcr@physics.carleton.ca> ;; Requires associated self-mode.el to be on your library path. ;; ;; This code based very strongly in the inferior lisp mode ;; found in shell.el ;; ; ; $Id: self.el,v 1.2 1993/05/14 21:45:01 richards Exp $ ; ; $Log: self.el,v $ ; Revision 1.2 1993/05/14 21:45:01 richards ; self-send-object doesn't always work quite right if you are at the ; very beginning of the object. Fixed it to go the beginning first. ; ; Revision 1.1 1993/05/14 21:12:11 richards ; Initial revision ; ; (require 'shell) (load-library "self-mode") (defvar inferior-self-mode-map nil) (if inferior-self-mode-map nil (progn (setq inferior-self-mode-map (copy-alist shell-mode-map)) (self-mode-commands inferior-self-mode-map) (define-key inferior-self-mode-map "\e\C-x" 'self-send-object))) (defvar inferior-self-program "Self" "*Program name for invoking an inferior Self with `run-self'. You might want to set this your favorite Snapshot, or set this variable in an Emacs file variable.") (defvar inferior-self-load-command "'%s' _RunScript\n" "*Format-string for building a Self expression to load a file. This format string should use %s to substitute a file name and should result in a Self expression that will command the inferior Self to load that file. ") (defvar inferior-self-prompt "^.*>" "*Regexp to recognize prompts from the inferior Self.") (defun inferior-self-mode () "Major mode for interacting with an inferior Self process. Runs a Self interpreter as a subprocess of Emacs, with Self I/O through an Emacs buffer. Variable inferior-self-program controls which Self interpreter is run. Variables inferior-self-prompt and inferior-self-load-command can customize this mode for different Self interpreters. Commands: DELETE converts tabs to spaces as it moves back. TAB indents for Self; with argument, shifts rest of expression rigidly with the current line. Meta-Control-Q does TAB on each line starting within following expression. Paragraphs are separated only by blank lines. Semicolons start comments. Return at end of buffer sends line as input. Return not at end copies rest of line to end and sends it. The following commands imitate the usual Unix interrupt and editing control characters: \\{shell-mode-map} Entry to this mode calls the value of self-mode-hook with no arguments, if that value is non-nil. Likewise with the value of shell-mode-hook. self-mode-hook is called after shell-mode-hook. You can send text to the inferior Self from other buffers using the commands process-send-region, process-send-string and \\[self-send-object]." (interactive) (kill-all-local-variables) (setq major-mode 'inferior-self-mode) (setq mode-name "Inferior Self") (setq mode-line-process '(": %s")) (use-local-map inferior-self-mode-map) (make-local-variable 'last-input-start) (setq last-input-start (make-marker)) (make-local-variable 'last-input-end) (setq last-input-end (make-marker)) (self-mode-variables) (run-hooks 'shell-mode-hook 'self-mode-hook 'inferior-self-mode-hook)) (defun run-self () "Run an inferior Self process, input and output via buffer *self*." (interactive) (switch-to-buffer (make-shell "self" inferior-self-program)) (cd (getenv "SELF_WORKING_DIR")) ; do this so the user knows where ; the Self is rooted. BUT! Beware, this ; likely is NOT where the snapshot was. (inferior-self-mode)) (defun self-send-object (display-flag) "Send the current object to the Self process made by M-x run-self. With argument, force redisplay and scrolling of the *self* buffer. Variable `inferior-self-load-command' controls formatting of the `load' form that is set to the Self process." (interactive "P") (or (get-process "self") (error "No current self process")) (save-excursion (beginning-of-object) (let ((begin (point)) (filename (format "/tmp/emself%d" (process-id (get-process "self"))))) (end-of-object) (if (= begin (point)) (message "Empty area. Please move inside object you want to send.") (progn (write-region begin (point) filename nil 'nomessage) (process-send-string "self" (format inferior-self-load-command filename))))) (if display-flag (let* ((process (get-process "self")) (buffer (process-buffer process)) (w (or (get-buffer-window buffer) (display-buffer buffer))) (height (window-height w)) (end)) (save-excursion (set-buffer buffer) (setq end (point-max)) (while (progn (accept-process-output process) (goto-char (point-max)) (beginning-of-line) (or (= (point-max) end) (not (looking-at inferior-self-prompt))))) (setq end (point-max)) (vertical-motion (- 4 height)) (set-window-start w (point))) (set-window-point w end))))) ; (message "Object sent.")) (defun self-send-object-and-go () "Send the current object to the inferior Self, and switch to *self* buffer." (interactive) (self-send-object nil) (switch-to-buffer "*self*"))